home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / 3D Buttons CDEF 1.0b6 / Source / 3D Buttons CDEF source / (3D CDEF++.68k.π) / LCDEFControl.h < prev    next >
Text File  |  1994-12-29  |  4KB  |  232 lines

  1. /*
  2.     Public domain by Zig Zichterman.
  3. */
  4. /*
  5.     LCDEFControl
  6.     
  7.     Base class for 3D Buttons controls. Most of the
  8.     code lives in LCDEFControl, with selected stuff 
  9.     overridden in derived classes.
  10.     
  11.     12/29/94    zz    h    add mButtonKind
  12.     12/20/94    zz    h    initial write
  13. */
  14. #pragma once
  15.  
  16. #include <Controls.h>
  17.  
  18. class LCDEFControl
  19. {
  20.     public :
  21.         typedef enum {
  22.             ButtonKind_PushButton    = 0,
  23.             ButtonKind_Checkbox,
  24.             ButtonKind_RadioButton,
  25.             ButtonKind_IconButton,
  26.             ButtonKind_Unknown
  27.         } ButtonKindT;
  28.             
  29.         enum {    IndentWhenHighlightedVariantFlag    = 0x04    };
  30.         
  31.         
  32.         static long
  33.         Main(
  34.             short            inVariation,
  35.             ControlHandle    ioControl,
  36.             short            inMsg,
  37.             long            ioParam);
  38.     
  39.     protected :
  40.         enum {
  41.             Grey_Black                = 0x0000,
  42.             Grey_White                = 0xFFFF,
  43.         
  44.             Grey_2BitInactiveFrame    = 0xAAAA,
  45.             
  46.             Grey_Background            = 0xEEEE
  47.             
  48.             
  49.         };
  50.         
  51.         // flag typedef/enums
  52.         typedef enum {
  53.             Flag_IsNot3D            = false,
  54.             Flag_Is3D                = true
  55.         } Is3DFlagT;
  56.         
  57.         typedef enum {
  58.             Flag_IsNotGreyCapable    = false,
  59.             Flag_IsGreyCapable        = true
  60.         } IsGreyCapableFlagT;
  61.     
  62.         typedef enum {
  63.             Flag_IsNotEnabled        = false,
  64.             Flag_IsEnabled            = true
  65.         } IsEnabledFlagT;
  66.         
  67.         typedef enum {
  68.             Flag_IsNotHighlighted    = false,
  69.             Flag_IsHighlighted        = true
  70.         } IsHighlightedFlagT;
  71.             
  72.         ControlHandle    mControl;
  73.         ButtonKindT        mButtonKind;
  74.         Boolean            mIndentWhenHighlighted;
  75.         Boolean            mUseWindowFont;
  76.         RGBColor        mBackgroundColor;
  77.         RGBColor        mInactiveFrameColor;
  78.         
  79.         LCDEFControl(
  80.             ControlHandle    inControl,
  81.             ButtonKindT        inButtonKind,
  82.             Boolean            inIndentWhenHighlighted,
  83.             Boolean            inUseWindowFont);
  84.         
  85.         virtual ~LCDEFControl();
  86.         
  87.         long
  88.         Dispatch(
  89.             short    inMsg,
  90.             long    ioParam);
  91.             
  92.         static void
  93.         UnpackVariant(
  94.             short            inVariation,
  95.             ButtonKindT &    outButtonKind,
  96.             Boolean &        outIndentWhenHighlighted,
  97.             Boolean &        outUseWindowFont);
  98.         
  99.         void
  100.         Draw(void);
  101.         
  102.         Boolean
  103.         HitTest(
  104.             Point    inHitPoint) const;
  105.             
  106.         virtual void
  107.         GetControlRgn(
  108.             RgnHandle    outControlRgn) const;
  109.         
  110.         // control handle accessors
  111.         void
  112.         GetControlRect(
  113.             Rect &    outControlRect) const;
  114.         
  115.         short
  116.         GetControlValue(void) const;
  117.     
  118.         StringPtr
  119.         GetControlTitle(void) const;
  120.         
  121.         Boolean
  122.         IsVisible(void) const;
  123.         
  124.         IsEnabledFlagT
  125.         IsEnabled(void) const;
  126.         
  127.         IsHighlightedFlagT
  128.         IsHighlighted(void) const;
  129.         
  130.         // drawing routines
  131.         void
  132.         CalcColors(void);
  133.         
  134.         virtual void
  135.         CalcColorsSelf(void) {}
  136.         
  137.         void
  138.         CalcBackgroundColor(void);
  139.         
  140.         void
  141.         CalcInactiveFrameColor(void);
  142.         
  143.         virtual void
  144.         CalcPartRects(void) {}
  145.         
  146.         void
  147.         ClipToControlRgn(void) const;
  148.         
  149.         void
  150.         DrawLoop(
  151.             Is3DFlagT            inIs3D,                    // can we draw 3D effects?
  152.             IsGreyCapableFlagT    inIsGreyCapable) const;    // can we use true grey for dimmed stuff?
  153.  
  154.         virtual void
  155.         SetBGColorToErase(
  156.             Is3DFlagT            inIs3D,
  157.             IsEnabledFlagT        inIsEnabled,
  158.             IsHighlightedFlagT    inIsHighlighted) const = 0;
  159.         
  160.         virtual void 
  161.         Erase(void) const = 0;
  162.         
  163.         void 
  164.         SetFGColorToFrame(
  165.             Is3DFlagT            inIs3D,
  166.             IsGreyCapableFlagT    inIsGreyCapable,
  167.             IsEnabledFlagT        inIsEnabled) const;
  168.         
  169.         virtual void 
  170.         DrawTitle(
  171.             Is3DFlagT            inIs3D,
  172.             IsHighlightedFlagT    inIsHighlighted,
  173.             Rect &                outTitleRect) const = 0;
  174.         
  175.         void
  176.         DimTitleIfNecessary(
  177.             IsGreyCapableFlagT    inIsGreyCapable,
  178.             IsEnabledFlagT        inIsEnabled,
  179.             const Rect &        inTitleRect) const;
  180.             
  181.         virtual void 
  182.         DrawFrame(void) const = 0;
  183.         
  184.         virtual void 
  185.         Draw3DEffects(void) const = 0;
  186.         
  187.         virtual void 
  188.         DrawValue(
  189.             Is3DFlagT            inIs3D,
  190.             IsEnabledFlagT        inEnabled,
  191.             IsHighlightedFlagT    inHighlight) const = 0;
  192.         
  193.         virtual void
  194.         InvertHighlight(void) const
  195.         {}
  196.         
  197.         // drawing utilities
  198.         static void
  199.         ForeGrey(
  200.             unsigned short    inGrey);
  201.         
  202.         static void
  203.         BackGrey(
  204.             unsigned short    inGrey);
  205.         
  206.         static void
  207.         Blend(
  208.             unsigned short    inGreyLevel,    // 0x0000 to 0xFFFF
  209.             const RGBColor    &inColor,        // color to mix with inGreyLevel
  210.             float            inPercentGrey,    // 1.0 = pure grey, 0.0 = pure color
  211.             RGBColor        &outBlend);
  212.     
  213.         static void
  214.         StringBox(
  215.             const StringPtr    inString,
  216.             const Rect &    inBox,
  217.             short            inAlign);
  218.         
  219.         static short
  220.         CountLines(
  221.             const StringPtr    inString);
  222.         
  223.         static short
  224.         StringHeight(
  225.             const StringPtr    inString);
  226.         
  227.         static void
  228.         DimRect(
  229.             const Rect &    inRect);
  230.  
  231. };
  232.